package sellControllers

import (
	"WEB/models"
	"WEB/models/sellModel"
	"fmt"
	"github.com/astaxie/beego"
	"html/template"
)

type SellBaseController struct {
	beego.Controller
}

func (this *SellBaseController) Prepare() {
	s := this.Ctx.Request.RequestURI
	user := (this.GetSession("sell_User"))
	//如果用户没有登录需要登录
	//如果用户登录了但是没有注册商铺需要注册商铺
	//如果用户注册了那么就放行
	switch user.(type) {
	case nil:
		if s == "/sell/login" || s == "/sell/register" || s == "/sell/error" {
			return
		} else {
			this.Redirect("/sell/login", 302)
		}
	case sellModel.SellUser:
		temp := user.(sellModel.SellUser)
		fmt.Println("temp", temp)
		this.Data["Username"] = temp.UserName
		if s == "/sell/store/reg" {
			return
		}

		if temp.UserStoreId == 0 {
			this.Redirect("/sell/store/reg", 302)
		} else {
			var store models.Stores
			store = this.GetSession("store").(models.Stores)
			this.Data["StoresLoopPic1"] = template.URL(store.StoresLoopPic1)
			this.Data["StoresLoopPic2"] = template.URL(store.StoresLoopPic2)
			this.Data["StoresLoopPic3"] = template.URL(store.StoresLoopPic3)
			this.Data["Store"] = store
			return
		}

	}
}
